package cn.wqk.rrtf.service;

import cn.wqk.rrtf.mapper.ChatMapper;
import cn.wqk.rrtf.mapper.CourseMapper;
import cn.wqk.rrtf.mapper.ChatMapper;
import cn.wqk.rrtf.pojo.Chat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChatServiceImpl implements ChatService {
    @Autowired
    private ChatMapper chatMapper;

    @Autowired
    private CourseMapper courseMapper;

    @Override
    public Integer insertChat(Chat chat){
        int i=chatMapper.insertChat(chat);
        System.out.println(i+":新增群组聊成功!");
        return i;
    }

    @Override
    public Integer insertChatByMemberId(Integer chatId,Integer memberId) {
        int i = chatMapper.insertChatByMemberId(chatId,memberId);
        return i;
    }

    @Override
    public Integer deleteChatByChatId(Integer chatId) {
        int i = chatMapper.deleteChatByChatId(2);
        System.out.println(i+":删除群组聊成功!");
        return i;
    }

    @Override
    public Integer deleteChatByMemberId(Integer chatId,Integer memberId) {
        int i = chatMapper.deleteChatByMemberId(chatId,memberId);
        return i;
    }

    @Override
    public Integer updateChatByChatId(Chat chat) {
        int i = chatMapper.insertChat(chat);
        System.out.println(i+":修改群组聊成功!");
        return i;
    }

    @Override
    public List<Chat> selectAllChat() {
        List<Chat> chatList = chatMapper.selectAllChat();
        for (Chat chat : chatList) {
            System.out.println(chat);
        }
        return chatList;
    }

    @Override
    public List<Chat> selectAllChatByType(String type) {
        List<Chat> chatList = chatMapper.selectAllChatByType(type);
        for (Chat chat : chatList) {
            System.out.println(chat);
        }
        return chatList;
    }

    @Override
    public Chat selectChatByChatId(Integer chatId) {
        Chat chat = chatMapper.selectChatByChatId(chatId);
        System.out.println(chat);
        return chat;
    }

    @Override
    public Chat selectChatByCourseId(Integer courseId) {
        Chat chat = chatMapper.selectChatByCourseId(1);
        System.out.println(chat);
        return chat;
    }

    @Override
    public List<Chat> selectChatByMemberId(Integer memberId) {
        List<Chat> chatList = chatMapper.selectChatByMemberId(1);
        for (Chat chat : chatList) {
            System.out.println(chat);
        }
        return chatList;
    }

    @Override
    public List<Chat> selectChatByCondition(Chat chat) {
        List<Chat> chatList = chatMapper.selectChatByCondition(chat);
        for (Chat chat1 : chatList) {
            System.out.println(chat1);
        }
        return chatList;
    }

    @Override
    public Integer selectChatNumberByChatId(Integer chatId) {
        Integer i = chatMapper.selectChatNumberByChatId(chatId);
        return i;
    }


}
